package com.gedeshidai.shumadevelop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gedeshidai.shumadevelop.common.BaseResponse;
import com.gedeshidai.shumadevelop.common.ResultUtils;
import com.gedeshidai.shumadevelop.mapper.HistoryMapper;
import com.gedeshidai.shumadevelop.model.entity.History;
import com.gedeshidai.shumadevelop.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HistoryServiceImpl extends ServiceImpl<HistoryMapper, History> implements HistoryService {
    @Autowired
    private HistoryMapper historyMapper;

    @Override
    public BaseResponse<Page<History>> getHistoryPageById(Long productId, int currentPage, int pageSize) {
        // 创建分页对象
        Page<History> page = new Page<>(currentPage, pageSize);

        // 构造查询条件
        QueryWrapper<History> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("action_time"); // 按 操作时间 降序序排序
        queryWrapper.eq("product_id", productId);// 查询 商品Id == 传参 的记录

        // 执行分页查询
        return ResultUtils.success(historyMapper.selectPage(page, queryWrapper));
    }
}
